// ctrlKeyListener.ts
export class KeyListener {
    private ctrlKeyPressed = false;

    constructor() {
        window.addEventListener('keydown', (e) => this.onKeyDown(e));
        window.addEventListener('keyup', (e) => this.onKeyUp(e));
    }

    /**
     * 按下control键
     */
    private onKeyDown(e: KeyboardEvent) {
        if (e.key === 'Control' || e.key === 'Meta') {
            this.ctrlKeyPressed = true;
        }
    }
    /**
     * 松开control键
     */
    private onKeyUp(e: KeyboardEvent) {
        if (e.key === 'Control' || e.key === 'Meta') {
            this.ctrlKeyPressed = false;
        }
    }

    public isCtrlPressed(): boolean {
        return this.ctrlKeyPressed;
    }
}
